import {useEffect} from "react";
import {useHttp} from "hooks/useHttp";
import {useAsync} from "hooks/useAsync";
import {User} from "types/user";
import {cleanObject} from "utils";

export const useUser = (param?: Partial<User>) => {
  const client = useHttp()
  const {run, ...res} = useAsync<User[]>()

  useEffect(() => {
    run(client("users", {data: cleanObject(param || {})}))
  }, [param])

  return res
}
